﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.Domain.PermisosModule.Entities;
using Cesave.Domain.Core.Specification;
using Cesave.Domain.PermisosModule.Resources;

namespace Cesave.Domain.PermisosModule.Contracts.CiclosFechas
{
	/// <summary>
	/// 
	/// </summary>
	public class CiclosFechasByDateRangeSpecification
		: Specification<CiclosFecha>
	{
		#region Private properties

		/// <summary>
		/// 
		/// </summary>
		private DateTime _fromDate = default(DateTime);

		/// <summary>
		/// 
		/// </summary>
		private DateTime _toDate = default(DateTime);

		#endregion

		#region Constructor

		/// <summary>
		/// 
		/// </summary>
		/// <param name="fromDate"></param>
		/// <param name="toDate"></param>
		public CiclosFechasByDateRangeSpecification(DateTime fromDate, DateTime toDate)
		{
			if (fromDate == DateTime.MinValue)
				throw new ArgumentException(Messages.exception_InvalidArgument, "fromDate");
			if (toDate == DateTime.MinValue)
				throw new ArgumentException(Messages.exception_InvalidArgument, "toDate");
			_fromDate = fromDate;
			_toDate = toDate;
		}

		#endregion

		#region Specification overrides

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public override System.Linq.Expressions.Expression<Func<CiclosFecha, bool>> SatisfiedBy()
		{
			Specification<CiclosFecha> specification = new TrueSpecification<CiclosFecha>();
			specification &= new DirectSpecification<CiclosFecha>(f => f.Inicio >= _fromDate);
			specification &= new DirectSpecification<CiclosFecha>(f => f.Fin <= _toDate);
			return specification.SatisfiedBy();
		}

		#endregion
	}
}
